'use client' import type { FC, SVGProps } from 'react' import React, { useEffect, useMemo } from 'react' import { usePathname } from 'next/navigation' import useSWR from 'swr' import { useTranslation } from 'react-i18next' import { useBoolean } from 'ahooks' import { Cog8ToothIcon, // CommandLineIcon, Squares2X2Icon, // eslint-disable-next-line sort-imports PuzzlePieceIcon, DocumentTextIcon, PaperClipIcon, QuestionMarkCircleIcon, } from '@heroicons/react/24/outline' import { Cog8ToothIcon as Cog8ToothSolidIcon, // CommandLineIcon as CommandLineSolidIcon, DocumentTextIcon as DocumentTextSolidIcon, } from '@heroicons/react/24/solid' import Link from 'next/link' import s from './style.module.css' import classNames from '@/utils/classnames' import { fetchDatasetDetail, fetchDatasetRelatedApps } from '@/service/datasets' import type { RelatedApp, RelatedAppResponse } from '@/models/datasets' import AppSideBar from '@/app/components/app-sidebar' import Divider from '@/app/components/base/divider' import AppIcon from '@/app/components/base/app-icon' import Loading from '@/app/components/base/loading' import FloatPopoverContainer from '@/app/components/base/float-popover-container' import DatasetDetailContext from '@/context/dataset-detail' import { DataSourceType } from '@/models/datasets' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import { LanguagesSupported } from '@/i18n/language' import { useStore } from '@/app/components/app/store' import { AiText, ChatBot, CuteRobot } from '@/app/components/base/icons/src/vender/solid/communication' import { Route } from '@/app/components/base/icons/src/vender/solid/mapsAndTravel' import { getLocaleOnClient } from '@/i18n' import { useAppContext } from '@/context/app-context' export type IAppDetailLayoutProps = { children: React.ReactNode params: { datasetId: string } } type ILikedItemProps = { type?: 'plugin' | 'app' appStatus?: boolean detail: RelatedApp isMobile: boolean } const LikedItem = ({ type = 'app', detail, isMobile, }: ILikedItemProps) => { return (
{type === 'app' && ( {detail.mode === 'advanced-chat' && ( )} {detail.mode === 'agent-chat' && ( )} {detail.mode === 'chat' && ( )} {detail.mode === 'completion' && ( )} {detail.mode === 'workflow' && ( )} )}
{!isMobile &&
{detail?.name || '--'}
} ) } const TargetIcon = ({ className }: SVGProps) => { return } const TargetSolidIcon = ({ className }: SVGProps) => { return } const BookOpenIcon = ({ className }: SVGProps) => { return } type IExtraInfoProps = { isMobile: boolean relatedApps?: RelatedAppResponse } const ExtraInfo = ({ isMobile, relatedApps }: IExtraInfoProps) => { const locale = getLocaleOnClient() const [isShowTips, { toggle: toggleTips, set: setShowTips }] = useBoolean(!isMobile) const { t } = useTranslation() useEffect(() => { setShowTips(!isMobile) }, [isMobile, setShowTips]) return
{(relatedApps?.data && relatedApps?.data?.length > 0) && ( <> {!isMobile &&
{relatedApps?.total || '--'} {t('common.datasetMenus.relatedApp')}
} {isMobile &&
{relatedApps?.total || '--'}
} {relatedApps?.data?.map((item, index) => ())} )} {!relatedApps?.data?.length && (
} >
{t('common.datasetMenus.emptyTip')}
{t('common.datasetMenus.viewDoc')}
)} } const DatasetDetailLayout: FC = (props) => { const { children, params: { datasetId }, } = props const pathname = usePathname() const hideSideBar = /documents\/create$/.test(pathname) const { t } = useTranslation() const { isCurrentWorkspaceDatasetOperator } = useAppContext() const media = useBreakpoints() const isMobile = media === MediaType.mobile const { data: datasetRes, error, mutate: mutateDatasetRes } = useSWR({ url: 'fetchDatasetDetail', datasetId, }, apiParams => fetchDatasetDetail(apiParams.datasetId)) const { data: relatedApps } = useSWR({ action: 'fetchDatasetRelatedApps', datasetId, }, apiParams => fetchDatasetRelatedApps(apiParams.datasetId)) const navigation = useMemo(() => { const baseNavigation = [ { name: t('common.datasetMenus.hitTesting'), href: `/datasets/${datasetId}/hitTesting`, icon: TargetIcon, selectedIcon: TargetSolidIcon }, // { name: 'api & webhook', href: `/datasets/${datasetId}/api`, icon: CommandLineIcon, selectedIcon: CommandLineSolidIcon }, { name: t('common.datasetMenus.settings'), href: `/datasets/${datasetId}/settings`, icon: Cog8ToothIcon, selectedIcon: Cog8ToothSolidIcon }, ] if (datasetRes?.provider !== 'external') { baseNavigation.unshift({ name: t('common.datasetMenus.documents'), href: `/datasets/${datasetId}/documents`, icon: DocumentTextIcon, selectedIcon: DocumentTextSolidIcon, }) } return baseNavigation }, [datasetRes?.provider, datasetId, t]) useEffect(() => { if (datasetRes) document.title = `${datasetRes.name || 'Dataset'} - 智脑云平台` }, [datasetRes]) const setAppSiderbarExpand = useStore(state => state.setAppSiderbarExpand) useEffect(() => { const localeMode = localStorage.getItem('app-detail-collapse-or-expand') || 'expand' const mode = isMobile ? 'collapse' : 'expand' setAppSiderbarExpand(isMobile ? mode : localeMode) }, [isMobile, setAppSiderbarExpand]) if (!datasetRes && !error) return return (
{!hideSideBar && : undefined} iconType={datasetRes?.data_source_type === DataSourceType.NOTION ? 'notion' : 'dataset'} />} mutateDatasetRes(), }}>
{children}
) } export default React.memo(DatasetDetailLayout)